﻿using AnnotateMe.Logic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;

namespace AnnotateMe.Test
{
    [TestClass()]
    public class SimpleTextQueryParserTest
    {
        [TestMethod()]
        public void EmptyQuery_YieldsEmptyResult()
        {
            SimpleTextQueryParser target = new SimpleTextQueryParser(); 
            string query = string.Empty; 
            IEnumerable<Tuple<string, string>> expected = Enumerable.Empty<Tuple<string, string>>();
            IEnumerable<Tuple<string, string>> actual;
            actual = target.Parse(query);
            CollectionAssert.AreEquivalent(expected.ToList(), actual.ToList());
        }

        [TestMethod()]
        public void OneWordQuery()
        {
            SimpleTextQueryParser target = new SimpleTextQueryParser();
            string query = "hello";
            IEnumerable<Tuple<string, string>> expected = Enumerable.Repeat<Tuple<string, string>>(new Tuple<string,string>("hello", string.Empty), 1);
            IEnumerable<Tuple<string, string>> actual;
            actual = target.Parse(query);
            CollectionAssert.AreEquivalent(expected.ToList(), actual.ToList());
        }

        [TestMethod()]
        public void OneWordWithAnnotation()
        {
            SimpleTextQueryParser target = new SimpleTextQueryParser();
            string query = "hello(world)";
            IEnumerable<Tuple<string, string>> expected = Enumerable.Repeat<Tuple<string, string>>(new Tuple<string, string>("hello", "world"), 1);
            IEnumerable<Tuple<string, string>> actual;
            actual = target.Parse(query);
            CollectionAssert.AreEquivalent(expected.ToList(), actual.ToList());
        }

        [TestMethod()]
        public void AnnotationWithASpace()
        {
            SimpleTextQueryParser target = new SimpleTextQueryParser();
            string query = "hello(hello world)";
            IEnumerable<Tuple<string, string>> expected =
                new[] 
                { 
                    new Tuple<string, string>("hello", "hello world"),
                };
            IEnumerable<Tuple<string, string>> actual;
            actual = target.Parse(query);
            CollectionAssert.AreEquivalent(expected.ToList(), actual.ToList());
        }

        [TestMethod()]
        public void Sentence()
        {
            SimpleTextQueryParser target = new SimpleTextQueryParser();
            string query = "hello(world) hello(hello)world)";
            IEnumerable<Tuple<string, string>> expected = 
                new [] 
                { 
                    new Tuple<string, string>("hello", "world"),
                    new Tuple<string, string>(" ", string.Empty),
                    new Tuple<string, string>("hello", "hello"),
                    new Tuple<string, string>("world)", string.Empty),
                };
            IEnumerable<Tuple<string, string>> actual;
            actual = target.Parse(query);
            CollectionAssert.AreEquivalent(expected.ToList(), actual.ToList());
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void IncompleteAnnotation()
        {
            SimpleTextQueryParser target = new SimpleTextQueryParser();
            string query = "hello(world";
            target.Parse(query).ToList();
        }
    }
}
